{include file="HttpRpc/header" /}

			<div class="content-page">
				<div class="content">
					<div class="container-fluid">
						<div class="row">
							<div class="col-12">
								<div class="card-box">
									<div class="row">
										<div class="col-12">
											<div class="filter-list">
											    <form  action="">
												<div class="row">
													<div class="col-md-2 col-xs-6">
														<div class="form-group">
															<label>项目</label>
															<select class="form-control" name="item">
																<option value="">全部</option>
																{foreach $item as $i=>$name}
																    <option value="{$name}" {if (isset($param.item) && $param.item==$name)} selected{/if}>{$name}</option>
																{/foreach}
															</select>
														</div>
													</div>
													<div class="col-md-2 col-xs-6">
														<div class="form-group">
															<label>分组</label>
															<select class="form-control" name="group">
																<option value="">全部</option>
																{foreach $group as $i=>$name}
																    <option value="{$name}" {if (isset($param.group) && $param.group==$name)} selected{/if}>{$name}</option>
																{/foreach}
															</select>
														</div>
													</div>
													<div class="col-md-2 col-xs-6">
														<label>状态</label>
														<select class="form-control" name="status">
															<option value="">全部</option>
															<option value="1" {if (isset($param.status) && $param.status==1)} selected{/if}>正常</option>
															<option value="2" {if (isset($param.status) && $param.status==2)} selected{/if}>关闭</option>
															<option value="3" {if (isset($param.status) && $param.status==3)} selected{/if}>故障</option>
														</select>
													</div>
													<div class="col-md-2 col-xs-6">
														<label>服务名称</label>
														<input type="text" class="form-control" name="title" value="{$param.title|default=''}">
													</div>
													<div class="col-md-2 col-xs-6">
														<label>服务地址</label>
														<input type="text" class="form-control" name="route" value="{$param.route|default=''}">
													</div>
													<div class="col-md-2 col-xs-12">
														<label style="color: #FFF;">1</label>
														<div>
															<button class="btn btn-primary waves-effect waves-light btn-sm"> 查詢 </button>
															{if ($auth.insert)}
															<button type="button" class="btn btn-success waves-effect waves-light btn-sm btn-sm mr-1" onclick="add('','','')"> 添加服务 </button>
															{/if}
														</div>
													</div>
													<div class="col-md-2 col-xs-12">
														<div style="margin-top:5px">
															<button type="button" id="autoReflush" class="btn btn-danger waves-effect waves-light btn-sm">开启自动刷新</button>
                                                                <div id="ms" style="width: auto;float: right;font-size: 13px;margin: 6px;"></div>
														</div>
													</div>
												</div>
												</form>
											</div>
											<div style="margin-top: 20px;">
												<div class="responsive-table-plugin">
													<div class="table-rep-plugin">
														<div class="table-responsive">
															<table id="datatable" class="table table-bordered dt-responsive nowrap">
																<thead>
																	<tr>
																		<th>序号</th>
																		<th>项目</th>
																		<th>分组</th>
																		<th>服务名称</th>
																		<th>服务地址</th>
																		<th>TCP-IP</th>
																		<th>端口</th>
																		<th>故障</th>
																		<th>当前请求数</th>
																		<th>评分</th>
																		<th>当前延迟</th>
																		<th>限制延迟(ms)</th>
																		<th>状态</th>

																		<th>每 * 分钟内</th>
																		<th>限制当前服务，最大接收 * 次请求</th>
																		<th>每 * 分钟内</th>
																		<th>限制单个IP，最大接收 * 次请求</th>
																		<th>操作</th>
																	</tr>
																</thead>
																<tbody>
                                                                    {foreach $arr as $k=>$v}
																	<tr>
																		<td>{$k+1}</td>
																		<td>{$v.item|default=''}</td>
																		<td>{$v.group|default=''}</td>
																		<td>{$v.title}</td>
																		<td><font color="#005aff">{$v.url}</font></td>
																		<td>{$v.ip}</td>
																		<td>{$v.port}</td>
																		<td>
																		    {if (isset($v['is_fault']) && $v.is_fault==1)}
																		        <font color="red">是</font>
																		    {else /}
																		        否
																		    {/if}
																		</td>
																		<td>{$v.request_num}</td>
																		<td>
																			{$v.score|default='100'}
																		</td>
																		<td>{$v.ping_ms|default='0'}ms</td>
																		<td>
																		    {if ($auth.update)}
																			    <input type="text" class="form-control" name="max_ms" value="{$v.max_ms|default='0'}" style="width:70px" onblur="input_save('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)">
																			{else /}
																			    {$v.max_ms|default='0'}
																			{/if}
																		</td>
																		<td>
																		    {if ($auth.update)}
    																			<span class="tg-list-item">
    																			     {if (isset($v['status']) && $v.status==2)}
    																			     <input class="tgl tgl-light" id="cb{$k}" type="checkbox">
    																				<label class="tgl-btn" for="cb{$k}" onclick="tab('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)" data-id="0"></label>
    																			     {else /}
    																			     <input class="tgl tgl-light" id="cb{$k}" type="checkbox" checked>
    																				<label class="tgl-btn" for="cb{$k}" onclick="tab('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)" data-id="2"></label>
    																			     {/if}
    																			</span>
    																		{else /}
																			     {if (isset($v['status']) && $v.status==2)}
																			     禁用
																			     {else /}
																			     启用
																			     {/if}
																			{/if}
																		</td>

																		<td>
																		    {if ($auth.update)}
																			<input type="text" class="form-control" name="route_minute" value="{$v.route_minute|default=''}" onblur="input_save('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)">
																			{else /}
																			{$v.route_minute|default=''}
																			{/if}
																		</td>
																		<td>
																		    {if ($auth.update)}
																			<input type="text" class="form-control" name="route_limit" value="{$v.route_limit|default=''}" onblur="input_save('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)">
																			{else /}
																			{$v.route_limit|default=''}
																			{/if}
																		</td>
																		<td>
																		    {if ($auth.update)}
																			<input type="text" class="form-control" name="ip_minute" value="{$v.ip_minute|default=''}" onblur="input_save('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)">
																			{else /}
																			{$v.ip_minute|default=''}
																			{/if}
																		</td>
																		<td>
																		    {if ($auth.update)}
																			<input type="text" class="form-control" name="ip_limit" value="{$v.ip_limit|default=''}" onblur="input_save('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}', this)">
																			{else /}
																			{$v.ip_limit|default=''}
																			{/if}
																		</td>

																		<td>
																		    {if ($auth.debug)}
																			<button type="button" class="btn btn-warning waves-effect waves-light btn-sm" style="padding: 2px 10px;" onclick="debug('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}')">调试</button>
																			{/if}
																		    {if ($auth.charts)}
																			<button type="button" class="btn btn-success waves-effect waves-light btn-sm" style="padding: 2px 10px;" onclick="charts('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}')"> 统计 </button>
																			{/if}
																			{if ($auth.copy)}
																			<button type="button" class="btn btn-info waves-effect waves-light btn-sm" style="padding: 2px 10px;" onclick="add('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}')">复制</button>
																			{/if}
																			{if ($auth.update)}
																			<button type="button" class="btn btn-primary waves-effect waves-light btn-sm" style="padding: 2px 10px;" onclick="update('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}')">修改</button>
																			{/if}
																			{if ($auth.delete)}
																			<button type="button" class="btn btn-danger waves-effect waves-light btn-sm" style="padding: 2px 10px;" onclick="deletes('{$v.class}', '{$v.function}', '{$v.ip}', '{$v.port}')">删除</button>
																			{/if}
																		</td>
																	</tr>
																	{/foreach}
																</tbody>
															</table>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			
{include file="HttpRpc/footer" /}


<script>
function debug(clas, fun, ip, port) {
    iframe.createIframe('调试节点', '/HttpRpc/debug?class='+clas+'&function='+fun+'&ip='+ip+'&port='+port, {
        'width':'100%',
        'height':'',
        'footer':'none'
    })
}
function charts(clas, fun, ip, port) {
    iframe.createIframe('请求统计', '/HttpRpc/charts?class='+clas+'&function='+fun+'&ip='+ip+'&port='+port, {
        'width':'100%',
        'height':'',
        'footer':'none'
    })
}
function add(clas, fun, ip, port) {
    iframe.createIframe('添加新节点', '/HttpRpc/create?class='+clas+'&function='+fun+'&ip='+ip+'&port='+port, {
        'width':'800px',
        'height':'500px',
        'function':'ajaxs'
    })
}
function ajaxs() {
    var _this = $('#myModal').find('iframe')[0];
    var bool  = _this.contentWindow.doSubimt();
    if (bool !== false) {
        alert(bool['msg']);
        window.location.reload();
    }
}
function update(clas, fun, ip, port) {
    iframe.createIframe('编辑节点', '/HttpRpc/update?class='+clas+'&function='+fun+'&ip='+ip+'&port='+port, {
        'width':'800px',
        'height':'500px',
        'function':'ajaxs'
    })
}
function tab(clas, fun, ip, port, _this) {
    // if (confirm('你确认切换该节点状态吗?')) {
        var status = $(_this).attr('data-id');
        $.ajax({
            type: 'post',
            data: {
                class:clas,
                function:fun,
                ip:ip,
                port:port,
                status:status,
            },
            url: "/HttpRpc/update_status",
            success: function(data) {
                var array = eval('('+data+')');
                if (array['code'] == '00') {
                    dialog(array['msg'], 'success');
                    if (status == 2) {
                        $(_this).attr('data-id', 0)
                    } else {
                        $(_this).attr('data-id', 2)
                    }
                } else {
                    dialog(array['msg'], 'error');
                }
            }
        });
    // }
}
function input_save(clas, fun, ip, port, _this) {
    var field = $(_this).attr('name');
    $.ajax({
        type: 'post',
        data: {
            class:clas,
            function:fun,
            ip:ip,
            port:port,
            field:field,
            num:$(_this).val(),
        },
        url: "/HttpRpc/input_save",
        success: function(data) {
            var array = eval('('+data+')');
            if (array['code'] == '00') {
                dialog(array['msg'], 'success');
            } else {
                dialog(array['msg'], 'error');
            }
        }
    });
}
function deletes(clas, fun, ip, port) {
    if (confirm('你确认删除该节点状态吗?')) {
        $.ajax({
            type: 'post',
            data: {
                class:clas,
                function:fun,
                ip:ip,
                port:port,
                status:status,
            },
            url: "/HttpRpc/delete",
            success: function(data) {
                var array = eval('('+data+')');
                if (array['code'] == '00') {
                    window.location.reload();
                } else {
                    dialog(array['msg'], 'error');
                }
            }
        });
    }
}
var fresh;
var stop = false;
$("#autoReflush").click(function(){
    if(!stop){
        $('#ms').html('每5秒自动刷新一次 ');
        //指定5秒刷新一次
        fresh = setInterval(function(){
            window.location.href='?reload=1';
        },5000); 
        $(this).text("关闭自动刷新");
        stop=true;
    }else{
        clearInterval(fresh);
        $(this).text("开启自动刷新");
        $('#ms').html('');
        stop = false;
    }
});
{if (!empty($param['reload']))}
$("#autoReflush").click();
{/if}
</script>